import sys
from pathlib import Path
import requests
import json

# Add the project root to the Python path
sys.path.append(str(Path(__file__).resolve().parent))

def test_api_endpoints():
    """测试管理员API端点是否正常工作"""
    base_url = "http://localhost:5000"
    
    endpoints = [
        "/api/dashboard/stats",
        "/api/employees",
        "/api/attendance?date_from=2023-01-01&date_to=2023-12-31",
        "/api/leave-requests?status=all",
        "/api/policies"
    ]
    
    print("开始测试API端点...")
    
    for endpoint in endpoints:
        try:
            url = f"{base_url}{endpoint}"
            print(f"测试: {url}")
            
            response = requests.get(url)
            
            if response.status_code == 200:
                data = response.json()
                print(f"  状态: 成功 (200)")
                print(f"  数据: {json.dumps(data, ensure_ascii=False, indent=2)[:200]}...")
            else:
                print(f"  状态: 失败 ({response.status_code})")
                print(f"  响应: {response.text}")
        except Exception as e:
            print(f"  错误: {str(e)}")
        
        print("-" * 50)
    
    print("API测试完成")

if __name__ == "__main__":
    test_api_endpoints() 